home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.10 Oct 93 / Dynamic MPW Menu / NewRunMenu
Encoding:
Text File  |  1993-07-15  |  4.9 KB  |  132 lines  |  [TEXT/MPS ]

  1. # Script: NewRunMenu
  2.  
  3. # A dynamically customizable menu for sublaunching commonly used files.
  4. # To install, type NewRunMenu in the Worksheet window and hit Enter.
  5.  
  6. # This adds a "Run" menu to the MPW menu bar.  It also creates a file called
  7. # UserStartup•RunMenu in the MPW folder (or the MPW PrefsFolder, if using MPW
  8. # 3.3 or newer), to re-create the menu each time you load MPW.
  9. # UserStartup•RunMenu is updated every time you add an item to the menu
  10.  
  11. # When you select Add Application, you can choose any application and specify
  12. # how it should appear on the menu.  When you select Add Document, you can
  13. # select a document, an application to open it with, and how it should
  14. # appear on the menu.
  15.  
  16. # The Run menu does not provide for DELETING an item.  To do that, open the
  17. # UserStartup•RunMenu file and delete the unwanted Addmenu lines.
  18.  
  19. # Important typographic notes:
  20.  
  21. # 1) The Add Application and Add Document menu item names start with one space,
  22. # so they sort alphabetically to the top of the menu.
  23.  
  24. # 2) The script for each AddMenu item is one long, continued command, so
  25. # most of the lines end with semi-colon ; and option-d ∂ characters.
  26.  
  27. # 3) Some of the prompt strings that appear in this script contain underscores.
  28. # I did this so they would be visible on a printed page.  However, in my
  29. # working copy of the script, the underscores are replaced with non-breaking
  30. # spaces (typed in MPW as option-space).  Strings containing non-breaking
  31. # spaces don't have to be placed in quotes.
  32.  
  33. # 4) Any place you see ... in this script, it really is 3 periods, not the
  34. # option-colon ellipsis … character.
  35.  
  36. # 5) Quote " apostrophe ' and grave accent ` are not interchangeable!
  37.  
  38. Set Exit 0
  39.  
  40. DeleteMenu Run ∑ Dev:Null
  41.  
  42. # "Add Application..." presents a Standard GetFile dialog, filtered for
  43. # applications only.  After you choose an application, it prompts you for
  44. # how the item should appear in the menu.  The default is the full path
  45. # and filename, which I usually edit to just the filename.
  46.  
  47. AddMenu Run ' Add Application...' ∂
  48. 'Begin ; ∂
  49.   Set Exit 0 ; ∂
  50.   Set menuChanged 0 ; ∂
  51.   Set theAppl "`getfilename -b Add -m Select_application... -t APPL`" ; ∂
  52.   Exit If {theAppl} == "" ; ∂
  53.   Set menuItem "`request -d {theAppl} How_should_the_menu_item_read...`" ; ∂
  54.   Exit If {menuItem} == "" ; AddMenu Run "{menuItem}" "{theAppl}" ; ∂
  55.   Set menuChanged 1 ; ∂
  56.   Unset theAppl ; ∂
  57.   Unset menuItem ; ∂
  58.   If ({menuChanged}) ; ∂
  59.     Set savedDir `Directory` ; ∂
  60.     Directory "{MPW}" ; ∂
  61.     Echo Set Exit 0 >"{PrefsFolder}"UserStartup•RunMenu ; ∂
  62.     Echo DeleteMenu Run ∂∑ Dev:Null >> "{PrefsFolder}"UserStartup•RunMenu ; ∂
  63.     AddMenu Run | Sort -u -quote >> "{PrefsFolder}"UserStartup•RunMenu ; ∂
  64.     Echo Set Exit 1 >> "{PrefsFolder}"UserStartup•RunMenu ; ∂
  65.     Execute "{PrefsFolder}"UserStartup•RunMenu ; ∂
  66.     Directory "{savedDir}" ; ∂
  67.     Unset savedDir ; ∂
  68.   End ; ∂
  69.   Unset menuChanged ; ∂
  70.   Set Exit 1 ; ∂
  71. End ∑ Dev:Null'
  72.  
  73. # Add Document... works a lot like Add Application..., except that you are
  74. # prompted to select TWO files.  The first can be any document, the second
  75. # must be an application which can open that document.
  76.  
  77. AddMenu Run ' Add Document...' ∂
  78. 'Begin ; ∂
  79.   Set Exit 0 ; ∂
  80.   Set menuChanged 0 ; ∂
  81.   Set theDoc "`getfilename -m Select_document_to_open...`" ; ∂
  82.   Exit If {theDoc} == "" ; ∂
  83.   Set theAppl "`getfilename -b With -m To_open_with... -t APPL`" ; ∂
  84.   Exit If {theAppl} == "" ; ∂
  85.   Set menuItem "`request -d {theDoc} How_should_the_menu_item_read...`" ; ∂
  86.   Exit If {menuItem} == "" ; ∂
  87.   AddMenu Run "{menuItem}" "{theAppl} {theDoc}" ; ∂
  88.   Set menuChanged 1 ; ∂
  89.   Export menuChanged ; ∂
  90.   Unset theAppl ; ∂
  91.   Unset menuItem ; ∂
  92.   If ({menuChanged}) ; ∂
  93.     Set savedDir `Directory` ; ∂
  94.     Directory "{MPW}" ; ∂
  95.     Echo Set Exit 0 >"{PrefsFolder}"UserStartup•RunMenu ; ∂
  96.     Echo DeleteMenu Run ∂∑ Dev:Null >> "{PrefsFolder}"UserStartup•RunMenu ; ∂
  97.     AddMenu Run | Sort -u -quote >> "{PrefsFolder}"UserStartup•RunMenu ; ∂
  98.     Echo Set Exit 1 >> "{PrefsFolder}"UserStartup•RunMenu ; ∂
  99.     Execute "{PrefsFolder}"UserStartup•RunMenu ; ∂
  100.     Directory "{savedDir}" ; ∂
  101.     Unset savedDir ; ∂
  102.   End ; ∂
  103.   Unset menuChanged ; ∂
  104.   Set Exit 1 ; ∂
  105. End ∑ Dev:Null'
  106.  
  107. # Add a separator line, which will appear between the default and user
  108. # configured menu items.
  109.  
  110. AddMenu Run '-' ''
  111.  
  112. # Create the UserStartup•RunMenu file.  This will be placed in either the
  113. # MPW folder, or MPW's PrefsFolder if using MPW 3.3 or newer.
  114.  
  115. # The UserStartup•RunMenu contains all of the commands needed to initialize
  116. # the Run menu, without any formatting or script comments.
  117.  
  118. Set savedDir `Directory`
  119. Directory "{MPW}"
  120. Echo Set Exit 0 > "{PrefsFolder}"UserStartup•RunMenu
  121. Echo DeleteMenu Run ∂∑ Dev:Null >> "{PrefsFolder}"UserStartup•RunMenu
  122. AddMenu Run >> "{PrefsFolder}"UserStartup•RunMenu
  123. Echo Set Exit 1 >> "{PrefsFolder}"UserStartup•RunMenu
  124. Directory "{savedDir}"
  125. Unset savedDir
  126.  
  127. # Announce completion
  128.  
  129. Alert -s Run Menu successfully installed.
  130.  
  131. # End of NewRunMenu script
  132.